package org.example.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.dao.DictTypeDao;
import org.example.entity.DictTypeEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("DictTypeService")//起一个名字
public class DictTypeServiceImpl extends ServiceImpl<DictTypeDao, DictTypeEntity>
        implements DictTypeService {
    @Override
    public List<DictTypeEntity> listByStatus(Integer status) {
        return lambdaQuery().eq(DictTypeEntity::getStatus, status).list();
    }
    private String sysId="DanZhao";

    @Override
    public IPage<DictTypeEntity> queryPage(Map<String, Object> params) {//业务逻辑具体实现
        LambdaQueryWrapper<DictTypeEntity> query = Wrappers.lambdaQuery();
        query.like(ObjectUtils.isNotEmpty(params.get("dictName")), DictTypeEntity::getDictName, params.get("dictName"));
        query.eq(ObjectUtils.isNotEmpty(params.get("dictType")), DictTypeEntity::getDictType, params.get("dictType"));
        query.eq(ObjectUtils.isNotEmpty(params.get("status")), DictTypeEntity::getStatus, params.get("status"));
        query.eq(DictTypeEntity::getSysId, sysId);
        query.orderByDesc(DictTypeEntity::getDictId);

        //分页参数
        int curPage = 1;
        int limit = 10;
        if (ObjectUtils.isNotEmpty(params.get("page"))) {
            curPage = Integer.parseInt(params.get("page").toString());
        }
        if (ObjectUtils.isNotEmpty(params.get("limit"))) {
            limit = Integer.parseInt(params.get("limit").toString());
        }

        IPage<DictTypeEntity> page = Page.of(curPage, limit);

        return baseMapper.selectPage(page, query);//实现了一个分页查询
    }

}
